package org.dromara.germbank.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.germbank.domain.BusPartnerClinic;
import org.dromara.germbank.domain.BusPartnerDoctor;
import org.dromara.germbank.domain.bo.BusPartnerClinicBo;
import org.dromara.germbank.domain.bo.BusPartnerDoctorBo;
import org.dromara.germbank.domain.vo.BusPartnerClinicVo;
import org.dromara.germbank.domain.vo.BusPartnerDoctorVo;
import org.dromara.germbank.mapper.BusPartnerDoctorMapper;
import org.dromara.germbank.service.BusPartnerDoctorService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 医生管理 实施类
 *
 * @author congxing
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class DoctorServiceImpl implements BusPartnerDoctorService {

    private final BusPartnerDoctorMapper busPartnerDoctorMapper;

    /**
     * 查询医生团队
     */
    @Override
    public TableDataInfo<BusPartnerDoctorVo> queryPageList(BusPartnerDoctorBo bo, PageQuery pageQuery) {

        Page<BusPartnerDoctorVo> page = busPartnerDoctorMapper.queryPageList(pageQuery.build(),this.buildQueryWrapper(bo));
        return TableDataInfo.build(page);
    }

    @Override
    public boolean checkDoctorNameUnique(BusPartnerDoctorBo bo) {
        return false;
    }

    @Override
    public int insertDoctor(BusPartnerDoctorBo bo) {
        return 0;
    }

    @Override
    public void updateDoctorData(BusPartnerDoctorBo bo) {

    }

    @Override
    public void deleteDoctorDataByIds(List<Long> bo) {

    }


    // 分页查询条件
    private Wrapper<BusPartnerDoctor> buildQueryWrapper(BusPartnerDoctorBo bo) {
        return Wrappers.<BusPartnerDoctor>lambdaQuery()
            // 逻辑删除字段（固定条件）
            .eq(BusPartnerDoctor::getDelFlag, SystemConstants.NORMAL)

            // 姓名（模糊）
            .like(StringUtils.isNotBlank(bo.getName()),
                BusPartnerDoctor::getName, bo.getName())

            // 手机号（精确）
            .eq(StringUtils.isNotBlank(bo.getMobile()),
                BusPartnerDoctor::getMobile, bo.getMobile())

            // 职位（精确）
            .eq(StringUtils.isNotBlank(bo.getTitle()),
                BusPartnerDoctor::getTitle, bo.getTitle())

            // 所在诊所名称（模糊）
            .like(StringUtils.isNotBlank(bo.getClinicName()),
                BusPartnerDoctor::getClinicName, bo.getClinicName())

            // 前端可见性（精确）
            .eq(StringUtils.isNotBlank(bo.getDisplayStatus()),
                BusPartnerDoctor::getDisplayStatus, bo.getDisplayStatus())

            // 排序
            .orderByAsc(BusPartnerDoctor::getMemberId);
    }
}
